/*
 * Copyright 2009 Jinbo Lin. All rights reserved.
 * 
 * cn.edu.pku.dao.impl HumanResourcesManagementSystem
 *
 * Created on 2009-12-20
 */
package cn.edu.pku.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.edu.pku.dao.SalarystandardmgtDao;
import cn.edu.pku.model.Salarystandardmgt;

/**
 * @author Jinbo Lin
 * 
 * 
 */
public class SalarystandardmgtDaoHibernate extends HibernateDaoSupport
		implements SalarystandardmgtDao {

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.edu.pku.dao.SalarystandardmgtDao#delete(int)
	 */
	@Override
	public void delete(int id) {
		if (null != this.get(id)) {
			this.getHibernateTemplate().delete(
					this.getHibernateTemplate()
							.get(Salarystandardmgt.class, id));
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.edu.pku.dao.SalarystandardmgtDao#delete(cn.edu.pku.model.Salarystandardmgt)
	 */
	@Override
	public void delete(Salarystandardmgt salarystandardmgt) {
		if (null != this.get(salarystandardmgt.getSalarystandardId())) {
			this.getHibernateTemplate().delete(salarystandardmgt);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.edu.pku.dao.SalarystandardmgtDao#findAll()
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Salarystandardmgt> findAll() {
		String hql = "from Salarystandardmgt";
		return this.getHibernateTemplate().find(hql);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.edu.pku.dao.SalarystandardmgtDao#get(int)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Salarystandardmgt get(int id) {
		String hql = "from Salarystandardmgt salarystandardmgt where salarystandardmgt.salarystandardId=?";
		List<Salarystandardmgt> salarystandardmgts = this
				.getHibernateTemplate().find(hql, new Integer(id));
		Salarystandardmgt salarystandardmgt = (null != salarystandardmgts && 0 != salarystandardmgts
				.size()) ? salarystandardmgts.get(0) : null;
		return salarystandardmgt;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.edu.pku.dao.SalarystandardmgtDao#save(cn.edu.pku.model.Salarystandardmgt)
	 */
	@Override
	public Serializable save(Salarystandardmgt salarystandardmgt) {
		if (null == this.get(salarystandardmgt.getSalarystandardId())) {
			this.getHibernateTemplate().save(salarystandardmgt);
		} else {
			salarystandardmgt = null;
		}
		return salarystandardmgt;

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.edu.pku.dao.SalarystandardmgtDao#update(cn.edu.pku.model.Salarystandardmgt)
	 */
	@Override
	public void update(Salarystandardmgt salarystandardmgt) {
		if (null != this.get(salarystandardmgt.getSalarystandardId())) {
			// this.getHibernateTemplate().saveOrUpdate(salarystandard);
			this.getHibernateTemplate().update(salarystandardmgt);
		}
	}

	/* (non-Javadoc)
	 * @see cn.edu.pku.dao.SalarystandardmgtDao#tDelete(int)
	 */
	@Override
	public void tDelete(int id) {
		Salarystandardmgt salarystandardmgt = this.get(id);
		salarystandardmgt.setRemark("Removed");
		this.save(salarystandardmgt);
	}
}
